package com.example.task1.ui.AllService.pet;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.PetDoctorBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class PetDoctorAdapter extends BaseAdapter<PetDoctorBean.RowsBean> {

    private Context context;
    private List<PetDoctorBean.RowsBean> data = new ArrayList<>();
    private TextView tvName;
    private TextView tvJobName;
    private TextView tvYear;
    private TextView tvGoodAt;
    private ImageView image;
    private Button btnCreate;

    public PetDoctorAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<PetDoctorBean.RowsBean> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.petdoctorlayout;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<PetDoctorBean.RowsBean> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, PetDoctorBean.RowsBean date) {
        tvName.setText("姓名：" + date.getName());
        tvJobName.setText("医生职称：" + date.getJobName());
        tvYear.setText("医龄：" + date.getWorkingYears());
        tvGoodAt.setText("擅长方向：" + date.getGoodAt());
        MyApplication.glide(image, date.getAvatar());
        btnCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context,PetCreateActivity.class,date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        tvName = (TextView) itemView.findViewById(R.id.tv_name);
        tvJobName = (TextView) itemView.findViewById(R.id.tv_jobName);
        tvYear = (TextView) itemView.findViewById(R.id.tv_year);
        tvGoodAt = (TextView) itemView.findViewById(R.id.tv_goodAt);
        image = (ImageView) itemView.findViewById(R.id.image);
        btnCreate = itemView.findViewById(R.id.btn_create);
    }
}
